import { Map } from "immutable"; // 深拷贝state 
import * as actionTypes from "../types/betcenter";
import { loginAPI } from "../../utils/url";
import { autoSelectLM } from "../actions/betcenterAction";

const initialState = Map({
    pankoulist:{},
    peilv:{},
    servenAward:{},
    gameinfo:{},
    apiRes:{},
    defaultitemcode:{},
    selectPeiyu:{},
    preOrderList:{},
    selectnamemoney:{},
    multiGroupOrder:{},
    lm:{
        leibie:0,
        playModle:1
    },
    autoSelectLM:false,
    LMReset:false
})

export default function reducer(state = initialState, action) {
    switch (action.type) {
      case actionTypes.REQUEST_PANKOU_LIST :
        let pankoulist = state.get("pankoulist")
        let defaultitemcode = state.get("defaultitemcode")
        pankoulist[action.data.datas.gameCode] = action.data.datas;
        defaultitemcode[action.data.datas.gameCode] = action.data.datas.defaultItemCode;
        state = state.set("pankoulist",pankoulist)
        state = state.set("apiRes",action.data)
        break;

        case actionTypes.REQUEST_GAME_INFO:
        state = state.set("gameinfo",action.data.datas)
        break;
      
        case actionTypes.REQUEST_SERVEN_AWARD_DETAIL:
        let type = action.data.type;
        let temp = state.get("servenAward")
        temp[type] = action.data.data.datas.list
        state = state.set("servenAward",temp)
        break;

        case actionTypes.REQUEST_PEILV_DATA :
        let peilv = state.get("peilv")
        let item = peilv[action.data.gameCode] = {}
        item[action.data.itemCode] = action.data.data.datas
        state = state.set("peilv",peilv)
        state = state.set("apiRes",action.data)
        break;

        case actionTypes.TEMP_SAVE_SELECTED_PEIYU:
        //存本地 防止用户刷新
        // var oldselectPeiyu = JSON.parse(localStorage.getItem("selectPeiyu"))
        // console.log(oldselectPeiyu,"pre");
        // Object.assign(oldselectPeiyu,action.data)
        // localStorage.setItem("selectPeiyu",JSON.stringify(action.data))
        // 添加到select 多彩种下注
        // var oldselectPeiyuModule = state.get("selectPeiyu")
        // Object.assign(oldselectPeiyuModule,action.data)
        state = state.set("selectPeiyu",action.data)
        break;

        case actionTypes.TEMP_SAVE_SELECTED_NAME_AND_MONEY:
        // localStorage.setItem("selectnamemoney",JSON.stringify(action.data))
        state = state.set("selectnamemoney",action.data)
        break

        case actionTypes.REQUEST_PREORDER_ITEMS:
        localStorage.setItem("preOrderList",action.data)
        state = state.set('preOrderList', action.data.datas);
        break;

        case actionTypes.REQUEST_MULTI_GROUP_ORDER:
        localStorage.setItem("multiGroupOrder",action.data)
        state = state.set("multiGroupOrder", action.data.datas)
        break;

        case actionTypes.CHANGE_LM_LEIBIE:
        let leibie = state.get("lm")
        leibie.leibie = action.data
        state = state.set("leibie",leibie)
        break;

        case actionTypes.CHANGE_LM_PLAYMODULE:
        state = state.set("playModle",state.get("lm").playModle = action.data)
        break;

        case actionTypes.AUTO_SELECT_LM:
        state = state.set("autoSelectLM",action.data)
        break;

        case actionTypes.LM_RESET:
        state = state.set("LMReset",action.data)
        break;

        case actionTypes.REMOVE_ALL_SELECT:
        state = state.set("selectPeiyu",{})
    }
    return state
}